//
//  GuideViewController.m
//  JHMall
//
//  Created by 王乐乐 on 16/7/18.
//  Copyright © 2016年 王乐乐. All rights reserved.
//

#import "GuideViewController.h"
#import "GuideCollectionViewCell.h"
#import "MainTabBarViewController.h"
#import "HengYouCai-Swift.h"

@interface GuideViewController ()

@end

@implementation GuideViewController

static NSString * const reuseIdentifier = @"GuideCollectionViewCellID";

- (instancetype)init{
    
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
   return  [self  initWithCollectionViewLayout:layout];
    
}

- (BOOL)prefersStatusBarHidden{
    return YES;
}

- (void)viewDidLoad {
  
    [super viewDidLoad];
    [self setUpCollectionView];
}

- (void)setUpCollectionView{
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[GuideCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    self.collectionView.pagingEnabled = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.bounces = NO;
}
#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    GuideCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.image = [UIImage imageNamed:[NSString stringWithFormat:@"Guide%ld",(long)indexPath.row]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (2 == indexPath.item) {
        NSDictionary * dic =[[WLFileManager readUserDataForKey:@"kJCWADGuideImageUrl"] mj_JSONObject];
        if ([dic[@"adIsShow"] boolValue]) {//是否显示广告
            JCWADGuideVC * vc = [[JCWADGuideVC alloc] init];
            vc.isFromGuide = YES;
            [UIApplication sharedApplication].keyWindow.rootViewController = [[BaseNavigationController alloc] initWithRootViewController:vc];
        }else{
            [UIApplication sharedApplication].keyWindow.rootViewController = [[MainTabBarViewController alloc] init];
        }
    }
}
@end
